package 链表与双指针.m03.d21.t07;

import 链表与双指针.LinkedListGenerator;
import 链表与双指针.ListNode;

class Solution {
    public static void main(String[] args) {
        int[] arr = {0,0,1,2,3,3,4,4,5};
        ListNode head = LinkedListGenerator.generateLinkedList(arr);
        head = deleteDuplicates(head);
        LinkedListGenerator.printLinkedList(head);
    }
    public static ListNode deleteDuplicates(ListNode head) {
        if (head == null) {
            return head;
        }
        
        ListNode dummy = new ListNode(0, head);

        ListNode cur = dummy;
        while (cur.next != null && cur.next.next != null) {
            if (cur.next.val == cur.next.next.val) {
                int x = cur.next.val;
                while (cur.next != null && cur.next.val == x) {
                    cur.next = cur.next.next;
                }
            } else {
                cur = cur.next;
            }
        }

        return dummy.next;
    }
}